/**
 * 使用folktale里的task函子处理异步任务
 */
const {task} = require("folktale/concurrency/task");
const fs =  require("fs");
const {split,find} = require("lodash/fp");

const readFile=(fileName)=>{
 return task((resolver)=>{
   fs.readFile(fileName,"utf-8",(error,data)=>{
      if(error){
        resolver.reject(error);
      }
      resolver.resolve(data)
   })
 })
}

readFile("package.json").map(split("\n"))
    .map(find(x=>x.includes("version")))
    .run()
    .listen({
      onRejected:(error)=>{
        console.log(error)
      },
      onResolved:(data)=>{
        console.log(data)
      }
    })
